<template>
  <div class="table">
    <table border="1">
      <thead>
        <th v-if="$store.state.sizeList.length">内存</th>
        <th v-if="$store.state.colorList.length">颜色</th>
      </thead>
      <tbody v-if="$store.state.objList.length">
        <tr v-for="(v, i) in list" :key="i">
          <td v-if="v.val">{{ v.val }}</td>
          <td v-if="v.name">{{ v.name }}</td>
        </tr>
      </tbody>
    </table>

    <div v-if="!$store.state.objList.length">
      <h4>暂无组合</h4>
    </div>
  </div>
</template>

<script>
import { ref, reactive, toRefs, computed } from "vue";
import { useStore } from "vuex";
export default {
  setup(props, { emit }) {
    let store = useStore();
    //   我们把传过来的数据 排序一下
    let obj = reactive({
      list: computed(() => {
        return store.state.objList.sort((a, b) => {
          console.log(parseInt(a));
          return parseInt(a.val) - parseInt(b.val);
        });
      }),
    });
    return { ...toRefs(obj) };
  },
  components: {},
};
</script>

<style lang="scss" scoped>
th,
td {
  width: 200px;
  text-align: center;
}
.table {
  width: 1280px;
  margin: 0 auto;
  h4 {
    margin: 30px;
    border: 0;
  }
}
</style>
